<?php

class cmsComponents extends sfComponents {

    public function executeBlog_block() {
        $this->items = BlogTable::getInstance()
                ->createQuery('r')
                ->select('r.id, t.info as info, t.body as body, r.image, r.slug, t.title as title')
                ->orderBy('r.updated_at DESC')
                ->leftJoin('r.Translation t')
                ->andWhere('t.title <> ""')
                ->addWhere('t.lang = ?', $this->getUser()->getCulture())
                ->limit(3)
                ->fetchArray();
    }

    public function executeComments() {
        $this->comments = CommentTable::getInstance()->getForItem($this->obj->getId());
    }

    public function executeSub_comment() {
        $this->comments = CommentTable::getInstance()->getForItem($this->item_id, $this->parent_id);
    }

    public function executeMenu() {
        $menu = MenuTable::getInstance()->createQuery()
                ->where('column_index = ?', $this->index)
                ->fetchOne();

        $this->menu_name = is_object($menu) ? $menu->getTitle() : null;

        if(is_object($menu)){
        $this->menu_items = MenuItemTable::getInstance()->createQuery('mi')
                ->where('menu_id = ?', $menu->getId())
                ->addWhere('t.lang = ?', $this->getUser()->getCulture())
                ->leftJoin('mi.Translation t')
                ->leftJoin('mi.Content c')
                ->select('t.title as title, t.id, mi.id, c.slug as slug, mi.route as route')
                ->fetchArray();
    }
    }

}